package com.cdsf.common.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
class LogAspect {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Pointcut("execution(public * com.cdsf.kennedy.*.service.*.*(..))")
    public void pointcuts() {
    }

    @Around("pointcuts()")
    public Object log(ProceedingJoinPoint proceedingJoinPoint) {
        Object response = null;
        try {
            Long start = System.currentTimeMillis();
            response = proceedingJoinPoint.proceed();
            Long end = System.currentTimeMillis();
            if (end - start > 10*1000) {
                MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
                String methodName = signature.getDeclaringTypeName() + "." + signature.getName();
                logger.info("方法[" + methodName + "]超过10秒");
            }
        } catch (Throwable e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return response;
    }

}
